{
  "properties" : { },
  "id" : "aacd20e9b1954880ac00a72b40c60fce",
  "script" : null,
  "groupId" : "bcdec4ef1ba74815bea2c09a20056b65",
  "name" : "添加",
  "createTime" : 1714063371928,
  "updateTime" : 1710949262891,
  "lock" : null,
  "createBy" : "管理员",
  "updateBy" : "管理员",
  "path" : "add",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ {
    "name" : "permission",
    "value" : "system:uhgl",
    "description" : "允许拥有该权限的访问",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "requestBody" : "{\r\n    \"name\": \"测试1号\",\r\n    \"username\": \"test1\",\r\n    \"password_new\": \"123456\",\r\n    \"memo\": \"ps: 这是测试数据\"\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : null,
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
import 'org.springframework.security.crypto.password.PasswordEncoder' as pwdEncoder;
import 'com.wiwf.model.security.service.SysTokenService' as sysTokenService;
import 'com.wiwf.model.security.service.SysUserService' as sysUserService;
import 'com.wiwf.model.mapper.admin.dao.SysUnitUserRoleMapper' as sysUnitUserRoleMapper;

    var user = sysTokenService.getTokenUser();

    if(body.password_new != null){
        body.password = pwdEncoder.encode(body.password_new);
    }

    if(body.userId != null){
        return sysUserService.update(body);
    }

    body.password_new = null;

    body.creatorId = user.getUserId();
    body.creatorName = user.getName();

    body.nonLock = 1;
    body.nonExpired = 1;
    body.nonExpiredC = 1;
    body.isEnabled = 1;

try {
    var bl = sysUserService.save(body);
} catch(e) {
    exit 500, '添加失败';
}

user = sysUserService.getByColumn('username', body.username);

return sysUnitUserRoleMapper.save({'unitId': 1, 'roleId': 2, 'userId': user.userId});